[dtrace-discuss] Re: dtrace in my kernel module, what''s the problem?

Roch Bourbonnais - Performance Engineering
2006-01-13T10:40:11Z

<Sorry If missed a previous answer here;>

It seems that your just getting fooled by the amazing design
of dtrace. If you have a kernel driver and you want to
dtrace into some of it''s functions you need not do anything.

Compile your driver (with whatever compiler suits you).
Install and load into a dtrace enabled kernel.

All your functions* are now instrumentable with dtrace:

	dtrace -n
''fbt::saa713x_print_ioctl:entry{@a[stack(20)]=count()}''

-----------------------------------------
* some hand crafted assembly will not be.


If you want DTRACE to know the types of the arguments to your
functions then you need to run ctf on your driver but that''s
not mandatory; You still have access to the arguments but
you need to cast them to proper types in your d-scripts.

if you want DTRACE probe point somewhere which is not at a
function boundary then you need to use the DTRACE_PROBEX()
(and #include <sys/sdt.h>). Then insert in you code:

	DTRACE_PROBE(myprobe)

That would show (once the driver is loaded) as

	dtrace -n ''sdt:::myprobe{}''

If you use myprobe in multiple functions; it will show up as
multiple probes to dtrace:

	dtrace -n ''sdt::f1:myprobe{}'' -n
''sdt::f2:myprobe{}''

HTH

-r


Matthias Pf?tzne r - Data Center  Ambassador - Strategy and Technology writes:
 > Perhaps I need to ask the question differently:
 >
 > What do I need to do to enable a kernel driver to be dtrace-able?
 >
 > Aka: What code do I need to put into the kernel driver source, so that it
 > becomes accessable via dtrace?
 >
 > I already learned, that my kernel driver will not become a new provider,
 > that''s OK.
 >
 > I already learned, that i need to "somehow register" my
variables, routines,
 > whatever to be "seen" by the dtrace kernel stuff...
 >
 > So, a "HowTo" for driver developpers might be helpful! (As I
have been
 > searching now for hours, but didn''t find any easy to follow
guidelines
 > yet... ;-( )
 >
 >         Matthias
 >
 > I (Matthias Pf?tzner - Data Center Ambassador - Strategy and Technology)
wrote:
 > > It can''t be that chapter...
 > >
 > > Because it starts:
 > >
 > > The Statically Defined Tracing (SDT) provider creates probes at sites
that a software programmer has formally designated. The SDT mechanism allows
programmers to consciously choose locations of interest to users of DTrace and
to convey some semantic knowledge about each location through the probe name.
The Solaris kernel has defined a handful of SDT probes, and will likely add more
over time. DTrace also provides a mechanism for user application developers to
define static probes, described in Chapter 34, Statically Defined Tracing for
User Applications.
 > >
 > > Still curious (and now, for the first time to the dtrace-alias),
 > >         Matthias
 > >
 > > I (Matthias Pf?tzner - Data Center Ambassador - Strategy and
Technology) wrote:
 > > > Adam,
 > > >
 > > > the problem is clear to me, but i didn''t find the
kernel chapter... ;-)
 > > >
 > > > Here''s the TOC:
 > > >
 > > >     * Index
 > > >     * Book Information
 > > >     * Preface
 > > >     * 1.  Introduction
 > > >     * 2.  Types, Operators, and Expressions
 > > >     * 3.  Variables
 > > >     * 4.  D Program Structure
 > > >     * 5.  Pointers and Arrays
 > > >     * 6.  Strings
 > > >     * 7.  Structs and Unions
 > > >     * 8.  Type and Constant Definitions
 > > >     * 9.  Aggregations
 > > >     * 10.  Actions and Subroutines
 > > >     * 11.  Buffers and Buffering
 > > >     * 12.  Output Formatting
 > > >     * 13.  Speculative Tracing
 > > >     * 14.  dtrace(1M) Utility
 > > >     * 15.  Scripting
 > > >     * 16.  Options and Tunables
 > > >     * 17.  dtrace Provider
 > > >     * 18.  lockstat Provider
 > > >     * 19.  profile Provider
 > > >     * 20.  fbt Provider
 > > >     * 21.  syscall Provider
 > > >     * 22.  sdt Provider
 > > >     * 23.  sysinfo Provider
 > > >     * 24.  vminfo Provider
 > > >     * 25.  proc Provider
 > > >     * 26.  sched Provider
 > > >     * 27.  io Provider
 > > >     * 28.  mib Provider
 > > >     * 29.  fpuinfo Provider
 > > >     * 30.  pid Provider
 > > >     * 31.  plockstat Provider
 > > >     * 32.  fasttrap Provider
 > > >     * 33.  User Process Tracing
 > > >     * 34.  Statically Defined Tracing for User Applications
 > > >     * 35.  Security
 > > >     * 36.  Anonymous Tracing
 > > >     * 37.  Postmortem Tracing
 > > >     * 38.  Performance Considerations
 > > >     * 39.  Stability
 > > >     * 40.  Translators
 > > >     * 41.  Versioning
 > > >     * Glossary
 > > >
 > > > Which chapter is the kernel tracing developing
"info-container"? The "sdt"
 > > > chapter, aka chapter 22?
 > > >
 > > > Still curious...
 > > >
 > > >         Matthias
 > > >
 > > > You (Adam Leventhal) write:
 > > > > Hi Matthias,
 > > > >
 > > > > Please post this question to dtrace-discuss at
opensolaris.org, but the short
 > > > > answer is that USDT is just for _user_ land binaries; for
(kernel) SDT
 > > > > check that chapter in the Solaris Dynamic Tracing Guide.
 > > > >
 > > > > Adam
 > > > >
 > > > > On Wed, Jan 11, 2006 at 09:46:45PM +0100, Matthias Pftzner
- Data Center Ambassador - Strategy and Technology wrote:
 > > > > > Folks,
 > > > > >
 > > > > > I try to add dtrace points to "my" kernel
module, but do get errors during
 > > > > > the compile.
 > > > > >
 > > > > >         /usr/sbin/dtrace -G -32 -s saa713xdtrace.d
obj-i386/saa713x-core.o obj-i386/saa713x-video.o obj-i386/saa713x-cards.o
obj-i386/saa713x-tvaudio.o obj-i386/saa713x-i2c.o
 > > > > >         dtrace: failed to link script saa713xdtrace:
an error was encountered while processing obj-i386/saa713x-core.o
 > > > > >
 > > > > > Here''s the code:
 > > > > >
 > > > > > bash-3.00$ cat saa713xdtrace.d
 > > > > > provider saa713xdtrace {
 > > > > >         probe routine__enter(string);
 > > > > >         probe routine__exit(string);
 > > > > > };
 > > > > > bash-3.00$
 > > > > >
 > > > > > And in the file saa713x-core.c I do have:
 > > > > >
 > > > > > #include <sys/sdt.h>
 > > > > >
 > > > > > void saa713x_print_ioctl(char *name, unsigned int cmd)
 > > > > > {
 > > > > >         const char *cmdnm;
 > > > > >         char *dir = "??";
 > > > > >
 > > > > >         DTRACE_PROBE1(saa713xdtrace, routine__enter,
"saa713x_print_ioctl");
 > > > > >         /*
 > > > > >          * IOR/read  == IOC_OUT == kernel->user
 > > > > >          * IOW/write == IOC_IN  == user->kernel
 > > > > >          */
 > > > > >         switch (cmd & IOC_INOUT) {
 > > > > >
 > > > > > et.al...
 > > > > >
 > > > > > So, what''s the problem, the error message
isn''t really helpful... ;-(
 > > > > >
 > > > > > All infos I found on this stuff is in:
 > > > > >
 > > > > >
http://docs.sun.com/app/docs/doc/817-6223/6mlkidlms?a=view
 > > > > >
 > > > > > Is there more? I did not find anything under:
 > > > > >
 > > > > >         http://www.sun.com/bigadmin/content/dtrace/
 > > > > >
 > > > > > Clueless,
 > > > > >         Matthias
 > > > > > --
 > > > > >
***********************************************************************
 > > > > > Matthias Pf?tzner
 > > > > > Data Center Ambassador
 > > > > > Strategy & Technology
 > > > > > Sun Microsystems GmbH                 Tel: +49 6103
752-394 (x65394)
 > > > > > Amp?restra?e 6                        Mobile: +49 172
8428766
 > > > > > 63225 Langen                          Fax: +49 6103
752-167
 > > > > > Germany
mailto:Matthias.Pfuetzner at Sun.COM
 > > > > >
***********************************************************************
 > > > >
 > > > > --
 > > > > Adam Leventhal, Solaris Kernel Development
http://blogs.sun.com/ahl
 > > >
 > > > --
 > > >
***********************************************************************
 > > > Matthias Pf?tzner
 > > > Data Center Ambassador
 > > > Strategy & Technology
 > > > Sun Microsystems GmbH                 Tel: +49 6103 752-394
(x65394)
 > > > Amp?restra?e 6                        Mobile: +49 172 8428766
 > > > 63225 Langen                          Fax: +49 6103 752-167
 > > > Germany                               mailto:Matthias.Pfuetzner
at Sun.COM
 > > >
***********************************************************************
 > >
 > > --
 > >
***********************************************************************
 > > Matthias Pf?tzner
 > > Data Center Ambassador
 > > Strategy & Technology
 > > Sun Microsystems GmbH                 Tel: +49 6103 752-394 (x65394)
 > > Amp?restra?e 6                        Mobile: +49 172 8428766
 > > 63225 Langen                          Fax: +49 6103 752-167
 > > Germany                               mailto:Matthias.Pfuetzner at
Sun.COM
 > >
***********************************************************************
 >
 > --
 > ***********************************************************************
 > Matthias Pf?tzner
 > Data Center Ambassador
 > Strategy & Technology
 > Sun Microsystems GmbH                 Tel: +49 6103 752-394 (x65394)
 > Amp?restra?e 6                        Mobile: +49 172 8428766
 > 63225 Langen                          Fax: +49 6103 752-167
 > Germany                               mailto:Matthias.Pfuetzner at Sun.COM
 > ***********************************************************************
 > _______________________________________________
 > dtrace-discuss mailing list
 > dtrace-discuss at opensolaris.org