Re: Question about 'for_each_kernel_tracepoint(...)' function
From: richard clark
Date: Thu Oct 20 2022 - 21:43:35 EST
On Thu, Oct 20, 2022 at 11:14 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Thu, 20 Oct 2022 17:32:57 +0800
> richard clark <richard.xnu.clark@xxxxxxxxx> wrote:
>
> > Hi,
> > Can this function only find the trace points defined in the kernel
>
> It should find all tracepoints.
I defined an event trace point in module B(in the header file):
...
#define TRACE_SYSTEM cus_tp
...
TRACE_EVENT(function_event_a,
/* all the data struct parameter is in form of pointer instead
of object */
TP_PROTO(enum event ev),
TP_ARGS(ev),
...
);
After the module B inserted, the output is:
root@robotics:/sys/kernel/debug/tracing# cat available_events | grep func
cus_tp:function_event_a
Then I inserted module A with below code snippet:
void fc(struct tracepoint *ktp, void *priv)
{
pr_info("events: %s\n", ktp->name);
}
static int module_A_init(void)
{
for_each_kernel_tracepoint(fc, NULL);
return 0;
}
Then I insert the module A into the system with module B is inserted,
the dmesg shows:
root@ robotics:/home/robotics/evt-tp# dmesg | grep func
[149421.718576] events: call_function_entry
[149421.718578] events: call_function_exit
[149421.718579] events: call_function_single_entry
[149421.718581] events: call_function_single_exit
So Steve you can see that the 'for_each_kernel_tracepoint' doesn't
find the event tp defined in module B, but that tp indeed shows in
/sys/kernel/debug/tracing/available_events.
Any comments about that?
>
> > image? I want to define a trace event in my kernel module A, then B
> > module to register a probe callback function for that event TP in A. I
> > want to kick off a timer in A and call the traced function
> > periodically, thus I can monitor the events happening in A from B.
>
> You could also export the tracepoint from A and reference it directly in B.
>
> >
> > Can I do that, is it possible?
> >
>
> Try it and find out. Why ask?
Ah, as you can see that I did it, but the result is not what I
expected :-). Help?
Richard
>
> -- Steve