From: Li Zefan on
Steven Rostedt wrote:
> From: Steven Rostedt <srostedt(a)redhat.com>
>
> This patch allows data to be passed to the tracepoint callbacks
> if the tracepoint was created to do so.
>
> If a tracepoint is defined with:
>
> DECLARE_TRACE_DATA(name, proto, args)
>
> Then a registered function can also register data to be passed
> to the tracepoint as such:
>
> DECLARE_TRACE_DATA(mytracepoint, TP_PROTO(int status), TP_ARGS(status));
>
> /* In the C file */
>
> DEFINE_TRACE(mytracepoint, TP_PROTO(int status), TP_ARGS(status));
>
> [...]
>
> trace_mytacepoint(status);
>
> /* In a file registering this tracepoint */
>
> int my_callback(int status, void *data)
> {
> struct my_struct my_data = data;
> [...]
> }
>
> [...]
> my_data = kmalloc(sizeof(*my_data), GFP_KERNEL);
> init_my_data(my_data);
> register_trace_mytracepoint_data(my_callback, my_data);
>
> The same callback can also be registered to the same tracepoint as long
> as the data registered is the same. Note, the data must also be used
> to unregister the callback:
>
> unregister_trace_mytracepoint_data(my_callback, my_data);
>
> Because of the data parameter, tracepoints declared this way can not have
> no args. That is:
>
> DECLARE_TRACE_DATA(mytracepoint, TP_PROTO(void), TP_ARGS());
>
> will cause an error, but the original DECLARE_TRACE still allows for this.
>
> The DECLARE_TRACE_DATA() will be used by TRACE_EVENT() so that it
> can reuse code and bring the size of the tracepoint footprint down.
> This means that TRACE_EVENT()s must have at least one argument defined.

We have to define at least on argument in TRACE_EVENT() even without
this patch, otherwise it'll cause compile error while expanding the
macros.

> This should not be a problem since we should never have a static
> tracepoint in the kernel that simply says "Look I'm here!".
>

We do have such a tracepoint. ;)

That is trace_power_end, and it uses a dummy argument merely for
passing compilation.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Steven Rostedt on
On Tue, 2010-04-27 at 17:08 +0800, Li Zefan wrote:
> Steven Rostedt wrote:

> > Because of the data parameter, tracepoints declared this way can not have
> > no args. That is:
> >
> > DECLARE_TRACE_DATA(mytracepoint, TP_PROTO(void), TP_ARGS());
> >
> > will cause an error, but the original DECLARE_TRACE still allows for this.
> >
> > The DECLARE_TRACE_DATA() will be used by TRACE_EVENT() so that it
> > can reuse code and bring the size of the tracepoint footprint down.
> > This means that TRACE_EVENT()s must have at least one argument defined.
>
> We have to define at least on argument in TRACE_EVENT() even without
> this patch, otherwise it'll cause compile error while expanding the
> macros.

OK, good to know that this is not a regression. The DECLARE_TRACE()
still allows now arguments, I spent a bit of time (more than I wanted
to) to make that work. Since I added a new DECLARE_TRACE_DATA() that
must have at least one argument, it is not a regression, because it is
new :-)

Thanks,

-- Steve

P.S.

I'll let these patches sit out for a week waiting for comments, and if
there are none, I'll repackage them (rebase as well) and send them out
for real.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Steven Rostedt on
On Wed, 2010-04-28 at 16:37 -0400, Mathieu Desnoyers wrote:
> * Steven Rostedt (rostedt(a)goodmis.org) wrote:
> > From: Steven Rostedt <srostedt(a)redhat.com>
> >
> > This patch allows data to be passed to the tracepoint callbacks
> > if the tracepoint was created to do so.
> >
> > If a tracepoint is defined with:
> >
> > DECLARE_TRACE_DATA(name, proto, args)
> >
> > Then a registered function can also register data to be passed
> > to the tracepoint as such:
> >
> > DECLARE_TRACE_DATA(mytracepoint, TP_PROTO(int status), TP_ARGS(status));
> >
> > /* In the C file */
> >
> > DEFINE_TRACE(mytracepoint, TP_PROTO(int status), TP_ARGS(status));
> >
> > [...]
> >
> > trace_mytacepoint(status);
> >
> > /* In a file registering this tracepoint */
> >
> > int my_callback(int status, void *data)
> > {
> > struct my_struct my_data = data;
> > [...]
> > }
> >
> > [...]
> > my_data = kmalloc(sizeof(*my_data), GFP_KERNEL);
> > init_my_data(my_data);
> > register_trace_mytracepoint_data(my_callback, my_data);
> >
> > The same callback can also be registered to the same tracepoint as long
> > as the data registered is the same. Note, the data must also be used
> > to unregister the callback:
> >
> > unregister_trace_mytracepoint_data(my_callback, my_data);
> >
> > Because of the data parameter, tracepoints declared this way can not have
> > no args. That is:
> >
> > DECLARE_TRACE_DATA(mytracepoint, TP_PROTO(void), TP_ARGS());
> >
> > will cause an error, but the original DECLARE_TRACE still allows for this.
> >
> > The DECLARE_TRACE_DATA() will be used by TRACE_EVENT() so that it
> > can reuse code and bring the size of the tracepoint footprint down.
> > This means that TRACE_EVENT()s must have at least one argument defined.
> > This should not be a problem since we should never have a static
> > tracepoint in the kernel that simply says "Look I'm here!".
> >
>
> I'm not convinced DECLARE_TRACE_DATA() is an appropriate name. Sounds
> confusing. What kind of data is this ? It is not obvious that this
> refers to callback private data.

Well, looking at the examples, it's pretty obvious what data is ;-)

>
> Why can't we just extend the existing DECLARE_TRACE() instead and add a
> "callback_data" argument (or something slightly less verbose) ? We can
> update all users anyway.
>
> We can also create a variant when there are no arguments passed:
>
> DECLARE_TRACE_NOARG()

I have no problem with modifying DECLARE_TRACE() this way. In fact that
was the original way I did it. I was just concerned about changing the
fact that DECLARE_TRACE() no longer allows for (void), and it breaks
your example in the samples dir.

We can make DECLARE_TRACE() add the callback data, and add a NOARG()
version for those that do not have any args.


>
> We had to do the same for the Linux kernel markers in the past. Then we
> can create a TRACE_EVENT_NOARG() macro if necessary.

Hmm, this may be difficult, since the TRACE_EVENT() requires passing of
a arg. I guess we can make NOARG will just ignore the "arg" value.

>
> I don't think it makes sense to require users to pass arguments. It
> should be possible to just say "I'm here". Cases where this could make
> sense includes cases where we'd only be interested in global variables
> at a specific tracepoint.

Well, as Li just pointed out, we already require it ;-)

Not a big deal, we can add a noarg version in the future, but this is
the cost for doing advance work with CPP.

-- Steve


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/