[DTrace-devel] [PATCH v5 01/11] libdtrace: Support multiple DTrace handles per process
Kris Van Hees
kris.van.hees at oracle.com
Wed Oct 7 09:26:25 UTC 2026
On Fri, Aug 21, 2026 at 05:10:49PM +0100, Alan Maguire wrote:
> For use cases like PCP we require multiple DTrace handles
> in a process; to fix this ensure we tie global map creation
> to the handle and also allow BEGIN and END probes to already
> exist. Later work can capitalize on efficiences like sharing
> kernel type info, but for now this is enough to make multiple
> instances work.
>
> Signed-off-by: Alan Maguire <alan.maguire at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
... with a small change, renaming dt_gmap_done to dt_gmaps_done (which I
should have done rom the beginning), and moving the dt_gmaps_done member
in dtrace_hdl_t at the end of the other booleans rather than putting it at
the very end of the struct.
Thanks for the patch - it certainly fixes a problem I introduced when I
did the BPF port. Making libdtrace be able to handle multiple instances
again is important!
> ---
> libdtrace/dt_bpf.c | 6 ++----
> libdtrace/dt_impl.h | 1 +
> libdtrace/dt_prov_dtrace.c | 6 +++++-
> 3 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
> index 146a66e3..be8a4229 100644
> --- a/libdtrace/dt_bpf.c
> +++ b/libdtrace/dt_bpf.c
> @@ -25,8 +25,6 @@
> #include <dt_btf.h>
> #include <port.h>
>
> -static boolean_t dt_gmap_done = 0;
> -
> #define BPF_CG_LICENSE "GPL";
>
> int
> @@ -1076,11 +1074,11 @@ int
> dt_bpf_gmap_create(dtrace_hdl_t *dtp)
> {
> /* If we already created the global maps, return success. */
> - if (dt_gmap_done)
> + if (dtp->dt_gmap_done)
> return 0;
>
> /* Mark global maps creation as completed. */
> - dt_gmap_done = 1;
> + dtp->dt_gmap_done = 1;
>
> #define CREATE_MAP(name) \
> if (gmap_create_##name(dtp) == -1) \
> diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
> index 5282efbd..7db2ba93 100644
> --- a/libdtrace/dt_impl.h
> +++ b/libdtrace/dt_impl.h
> @@ -433,6 +433,7 @@ struct dtrace_hdl {
> dt_list_t dt_lib_dep_sorted; /* dependency sorted library list */
> dt_global_pcap_t dt_pcap; /* global tshark/pcap state */
> char *dt_freopen_filename; /* filename for freopen() action */
> + boolean_t dt_gmap_done; /* global map created */
> };
>
> /*
> diff --git a/libdtrace/dt_prov_dtrace.c b/libdtrace/dt_prov_dtrace.c
> index 4b788507..8118ab23 100644
> --- a/libdtrace/dt_prov_dtrace.c
> +++ b/libdtrace/dt_prov_dtrace.c
> @@ -243,7 +243,11 @@ static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
> close(fd);
> }
> free(spec);
> - if (rc == -1)
> + /*
> + * Multiple handles in a process mean we may have BEGIN/END
> + * uprobe events already.
> + * */
> + if (rc == -1 && errno != EEXIST)
> return -ENOENT;
>
> /* open format file */
> --
> 2.43.5
>
More information about the DTrace-devel
mailing list