Page MenuHomeFreeBSD

libdtrace: add support for lazyload mode
ClosedPublic

Authored by markj on Apr 1 2015, 10:56 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 14, 5:38 AM
Unknown Object (File)
Tue, Nov 26, 9:11 PM
Unknown Object (File)
Oct 23 2024, 4:30 AM
Unknown Object (File)
Oct 15 2024, 11:35 AM
Unknown Object (File)
Oct 1 2024, 5:03 AM
Unknown Object (File)
Sep 30 2024, 12:23 PM
Unknown Object (File)
Sep 26 2024, 5:45 PM
Unknown Object (File)
Sep 25 2024, 6:07 AM
Subscribers

Details

Summary

When applications using USDT are compiled with -x lazyload, dtrace(1)
will not link drti.o into the generated object file. As a result, probes
are not registered automatically when the application starts; when
dtrace(1) attaches to a process running this application, it will
discover any DOF sections and register them on the process' behalf. This
reduces startup cost and kernel memory consumption for applications that
use USDT, which is important for USDT providers in commonly-used libraries,
such as libthr (for the plockstat provider).

libdtrace relies on some libproc interfaces to open files and register
DOF in the context of the target process. FreeBSD doesn't have interfaces
to support this, so we instead add a pid field to dof_helper_t. The ioctl
handler then verifies that DOF registration is either done by the process
itself (via drti.o, typically), or by a process that is ptracing the
target process (dtrace(1), typically).

Some light refactoring is needed to support DOF registration by one
process on behalf of another. I avoided adding #ifdefs for this since it
gets messy, and because the changes could be adopted upstream.

Test Plan

DTrace test suite, tested with toy USDT providers in an executable and a shared library.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

markj retitled this revision from to libdtrace: add support for lazyload mode..
markj edited the test plan for this revision. (Show Details)
markj updated this object.
markj retitled this revision from libdtrace: add support for lazyload mode. to libdtrace: add support for lazyload mode.Apr 1 2015, 11:03 PM
markj added reviewers: rpaulo, DTrace.
rpaulo edited edge metadata.

This is cool: it let us keep the /dev/dtrace char devices with strict permissions because the probes will only be registered when you run dtrace(1), which usually has root privileges.

cddl/contrib/opensolaris/lib/libdtrace/common/drti.c
150 ↗(On Diff #4587)

#ifdef FreeBSD?

This revision is now accepted and ready to land.Apr 2 2015, 3:56 AM
In D2203#5, @rpaulo wrote:

This is cool: it let us keep the /dev/dtrace char devices with strict permissions because the probes will only be registered when you run dtrace(1), which usually has root privileges.

Right, that's another good application of this. Another is the ability to trace a process that started after dtraceall.ko was loaded.

cddl/contrib/opensolaris/lib/libdtrace/common/drti.c
150 ↗(On Diff #4587)

Oops, thanks.

sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
1419 ↗(On Diff #4587)

I need to bump this to 4 since dof_helper_t is changing. I'll also provide a compat ioctl so that this can be MFCed.

In D2203#8, @markj wrote:
In D2203#5, @rpaulo wrote:

This is cool: it let us keep the /dev/dtrace char devices with strict permissions because the probes will only be registered when you run dtrace(1), which usually has root privileges.

[...]Another is the ability to trace a process that started after dtraceall.ko was loaded.

... started _before_ dtraceall.ko was loaded.

sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
1419 ↗(On Diff #4587)

Never mind - sizeof(dof_helper_t) is part of the ioctl encoding, so I don't need to change the ioctl number. I'll add the compat ioctl when I MFC.

markj edited edge metadata.
  • Only set dofhp_pid on FreeBSD.
  • Copy DOF out of the target process before passing it to the kernel.
This revision now requires review to proceed.Apr 4 2015, 2:44 AM
markj edited edge metadata.
rpaulo edited edge metadata.
This revision is now accepted and ready to land.Apr 4 2015, 5:06 AM
markj updated this revision to Diff 4734.

Closed by commit rS281257 (authored by @markj).