Skip to content

Commit 54b6b4a

Browse files
mhiramatrostedt
authored andcommitted
Documentation: probes: Update fprobe on function-graph tracer
Update fprobe documentation for the new fprobe on function-graph tracer. This includes some bahvior changes and pt_regs to ftrace_regs interface change. Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com> Cc: Florent Revest <revest@chromium.org> Cc: Martin KaFai Lau <martin.lau@linux.dev> Cc: bpf <bpf@vger.kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Alan Maguire <alan.maguire@oracle.com> Cc: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/173519010442.391279.10732749889346824783.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 0c2dd44 commit 54b6b4a

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

Documentation/trace/fprobe.rst

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ Fprobe - Function entry/exit probe
99
Introduction
1010
============
1111

12-
Fprobe is a function entry/exit probe mechanism based on ftrace.
13-
Instead of using ftrace full feature, if you only want to attach callbacks
14-
on function entry and exit, similar to the kprobes and kretprobes, you can
12+
Fprobe is a function entry/exit probe based on the function-graph tracing
13+
feature in ftrace.
14+
Instead of tracing all functions, if you want to attach callbacks on specific
15+
function entry and exit, similar to the kprobes and kretprobes, you can
1516
use fprobe. Compared with kprobes and kretprobes, fprobe gives faster
1617
instrumentation for multiple functions with single handler. This document
1718
describes how to use fprobe.
@@ -91,12 +92,14 @@ The prototype of the entry/exit callback function are as follows:
9192

9293
.. code-block:: c
9394
94-
int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, void *entry_data);
95+
int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data);
9596
96-
void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, void *entry_data);
97+
void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data);
9798
98-
Note that the @entry_ip is saved at function entry and passed to exit handler.
99-
If the entry callback function returns !0, the corresponding exit callback will be cancelled.
99+
Note that the @entry_ip is saved at function entry and passed to exit
100+
handler.
101+
If the entry callback function returns !0, the corresponding exit callback
102+
will be cancelled.
100103

101104
@fp
102105
This is the address of `fprobe` data structure related to this handler.
@@ -112,19 +115,28 @@ If the entry callback function returns !0, the corresponding exit callback will
112115
This is the return address that the traced function will return to,
113116
somewhere in the caller. This can be used at both entry and exit.
114117

115-
@regs
116-
This is the `pt_regs` data structure at the entry and exit. Note that
117-
the instruction pointer of @regs may be different from the @entry_ip
118-
in the entry_handler. If you need traced instruction pointer, you need
119-
to use @entry_ip. On the other hand, in the exit_handler, the instruction
120-
pointer of @regs is set to the current return address.
118+
@fregs
119+
This is the `ftrace_regs` data structure at the entry and exit. This
120+
includes the function parameters, or the return values. So user can
121+
access thos values via appropriate `ftrace_regs_*` APIs.
121122

122123
@entry_data
123124
This is a local storage to share the data between entry and exit handlers.
124125
This storage is NULL by default. If the user specify `exit_handler` field
125126
and `entry_data_size` field when registering the fprobe, the storage is
126127
allocated and passed to both `entry_handler` and `exit_handler`.
127128

129+
Entry data size and exit handlers on the same function
130+
======================================================
131+
132+
Since the entry data is passed via per-task stack and it has limited size,
133+
the entry data size per probe is limited to `15 * sizeof(long)`. You also need
134+
to take care that the different fprobes are probing on the same function, this
135+
limit becomes smaller. The entry data size is aligned to `sizeof(long)` and
136+
each fprobe which has exit handler uses a `sizeof(long)` space on the stack,
137+
you should keep the number of fprobes on the same function as small as
138+
possible.
139+
128140
Share the callbacks with kprobes
129141
================================
130142

@@ -165,8 +177,8 @@ This counter counts up when;
165177
- fprobe fails to take ftrace_recursion lock. This usually means that a function
166178
which is traced by other ftrace users is called from the entry_handler.
167179

168-
- fprobe fails to setup the function exit because of the shortage of rethook
169-
(the shadow stack for hooking the function return.)
180+
- fprobe fails to setup the function exit because of failing to allocate the
181+
data buffer from the per-task shadow stack.
170182

171183
The `fprobe::nmissed` field counts up in both cases. Therefore, the former
172184
skips both of entry and exit callback and the latter skips the exit

0 commit comments

Comments
 (0)