Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Sep 2014 16:44:13 -0400
From:      Mark Johnston <markj@freebsd.org>
To:        Shrikanth Kamath <shrikanth07@gmail.com>
Cc:        freebsd-hackers@freebsd.org, freebsd-dtrace@freebsd.org
Subject:   Re: Usage of DTRACE_PROBE macro from sdt.h in kernel modules
Message-ID:  <20140902204413.GC59246@charmander.home>
In-Reply-To: <CAEOAkMWw07D-XTx8JXvVjU%2BOjUQbKcOZmYoLvzSGA=80B8q-tw@mail.gmail.com>
References:  <CAEOAkMWw07D-XTx8JXvVjU%2BOjUQbKcOZmYoLvzSGA=80B8q-tw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Sep 02, 2014 at 01:24:47PM -0700, Shrikanth Kamath wrote:
> Adding a DTRACE_PROBE(name) in a kernel module does not create the SDT
> probe. I added
> the following to the module file before using DTRACE_PROBE.

Somewhat confusingly, DTRACE_PROBE* shouldn't be used in the kernel. It's
there for compatibility with the DTrace probes in ZFS, which use the SDT
interfaces in illumos. The SDT_PROBE* macros should be used instead. If
you grep the kernel sources, you'll find lots of examples of SDT providers
and probes.

> #include "opt_kdtrace.h"
> #include <sys/sdt.h>
> 
> function_foo() {
> ...
> +       DTRACE_PROBE(name);
> ...
> }
> 
> I figured the sdt.h does declare SDT_PROVIDER_DECLARE(set); but that
> is not helping. Was expecting a sdt probe added under provider 'set'.

SDT_PROVIDER_DEFINE() is used to define a provider.
SDT_PROVIDER_DECLARE() just adds a declaration, so it won't result in
anything being added to the SDT provider linker set in the corresponding
kld.

So SDT_PROVIDER_DEFINE() should be used once to define a new provider,
and the provider can be made visible across multiple files using
SDT_PROVIDER_DECLARE().

> 
> The SDT probe creation returns from sdt_kld_load from here
> 
>        if (linker_file_lookup_set(lf, "sdt_providers_set", &begin, &end, NULL))
>                 return;
> 
> I did a nm on the kernel module and did not find anything matching
> "sdt_providers_set"
> 
> nm -a module.ko | grep sdt
> 
> 00000000 r __set_sdt_probes_set_sym_sdt_sdt______func____LINE__.103790
> 
>          U __start_set_sdt_probes_set
> 
>          U __stop_set_sdt_probes_set
> 
>          U sdt_probe_func
> 
>          U sdt_provider_sdt
> 
> 000006c0 d sdt_sdt______func____LINE__.103789
> 
> Can't seem to figure how to get the SDT probe created by using
> DTRACE_PROBE macro in a kernel module.

In addition to the comments above, I suggest taking a look at the SDT(9)
man page, which has a few examples.

Thanks,
-Mark



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140902204413.GC59246>