Usage of DTRACE_PROBE macro from sdt.h in kernel modules

Mark Johnston markj at freebsd.org
Wed Sep 3 23:50:24 UTC 2014


On Wed, Sep 03, 2014 at 02:09:48PM -0700, Shrikanth Kamath wrote:
> Thanks  Mark/Andriy for helping with this query. I checked the define
> KDTRACE_HOOKS define that is set. Rather I tried this, I defined a
> fake provider just to check if that prompts sdt_kld_load to create the
> SDT probes from my kernel module.
> 
> + SDT_PROVIDER_DEFINE(fake);
> And it does help load the SDT probes I created, even though I am not
> using the fake provider I defined. I feel that sdt_kld_load is flawed
> when it is looking for sdt_providers_set in the module. It expects at
> least a provider define and cannot use one of the defined ones in
> kernel by just declaring it.
> 
>          if (linker_file_lookup_set(lf, "sdt_providers_set", &begin,
> &end, NULL))
>              return;

You're completely right; this issue was fixed in
http://svnweb.freebsd.org/base?view=revision&revision=267706

> 
> I intended to use DTRACE_PROBE() instead of the conventional
> SDT_PROBE_DEFINE/SDT_PROBE usage because I wanted to create probes
> which have probe names based on __LINE__ macro...disclaimer...this was
> just for experiment sakes...
> 
> E.g
> func_foo()
> {
>     ....
>     if ()
>         return EINVAL;
>     ...
>     if ()
>         return EINVAL;
>     ...
>     if ()
>         return EINVAL;
> }
> 
> which I replaced with
> func_foo()
> {
>     ...
>     if ()
>         RETSDT(func_foo, EINVAL);
>     ...
>     if ()
>         RETSDT(func_foo, EINVAL);
>     ...
>     if ()
>         RETSDT(func_foo, EINVAL);
> }
> where RETSDT macro and other macros are defined as
> 
> #define PROBENAME1(func, __LINE__) func ## __LINE__
> #define PROBENAME(func, line) PROBENAME1(func, line)
> 
> #define RETSDT(func, error_code)       \
>     do {                                                    \
>         DTRACE_PROBE(PROBENAME(func, __LINE__));\
>         return (error_code);               \
>     } while (0)
> 
> With the fake provider I defined I get to see and execute my SDT probes
> % dtrace -l | grep func_foo
> 56455        sdt          netstack                 func_foo1592
> 
> Here netstack is my module, and I have a probe name based on __LINE__
> which is 1592.

Why not just use a single probe and make the line number and function
name arguments to the probe? That is, write something like

#define RETSDT(error_code) do { \
	DTRACE_PROBE2(error__return, __func__, __LINE__)
	return (error_code);
} while (0)

> Don't know if that is good way to do it but using SDT_PROBE_DEFINE
> looks like a problem because of the presence of __LINE__ in the
> probename.
> 
> Thanks for reaching out...
> --
> Shrikanth R K
> 
> On Wed, Sep 3, 2014 at 6:04 AM, Andriy Gapon <avg at freebsd.org> wrote:
> > on 02/09/2014 23:44 Mark Johnston said the following:
> >> Somewhat confusingly, DTRACE_PROBE* shouldn't be used in the kernel.
> >
> > But it can be used.
> >
> > Shrikanth, please double check that KDTRACE_HOOKS is defined when you compile
> > your module.
> >
> > --
> > Andriy Gapon


More information about the freebsd-hackers mailing list